//package com.after.saas.oauth.service.impl;
//
//import com.after.saas.oauth.domain.SecurityUser;
//import com.after.saas.oauth.domain.UserDTO;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.security.core.authority.SimpleGrantedAuthority;
//import org.springframework.security.core.userdetails.User;
//import org.springframework.security.core.userdetails.UserDetails;
//import org.springframework.security.core.userdetails.UserDetailsService;
//import org.springframework.security.core.userdetails.UsernameNotFoundException;
//import org.springframework.security.crypto.password.PasswordEncoder;
//import org.springframework.security.oauth2.provider.token.TokenStore;
//import org.springframework.security.oauth2.provider.token.store.redis.JdkSerializationStrategy;
//import org.springframework.security.oauth2.provider.token.store.redis.RedisTokenStoreSerializationStrategy;
//import org.springframework.stereotype.Component;
//
//import java.util.ArrayList;
//import java.util.Arrays;
//import java.util.Collections;
//import java.util.List;
//
///**
// * UserDetailsServiceImpl
// *
// * @author hjchen
// * @date 2019/3/30
// */
//@Slf4j
//@Component(value = "kiteUserDetailsService")
//public class UserDetailsServiceImpl implements UserDetailsService {
//
//
//    @Autowired
//    private PasswordEncoder passwordEncoder;
//
//    private RedisTokenStoreSerializationStrategy serializationStrategy = new JdkSerializationStrategy();
//
//    @Autowired
//    private TokenStore redisTokenStore;
//
//    @Override
//    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
//        log.info("usernameis:" + username);
//        // 查询数据库操作
//        if(!username.equals("admin")){
//            throw new UsernameNotFoundException("the user is not found");
//        }else{
//            // 用户角色也应在数据库中获取
//            String role = "ROLE_ADMIN";
//            List<SimpleGrantedAuthority> authorities = new ArrayList<>();
//            authorities.add(new SimpleGrantedAuthority(role));
//            // 线上环境应该通过用户名查询数据库获取加密后的密码
//            String password = passwordEncoder.encode("123456");
//            // 返回默认的 User
//            // return new org.springframework.security.core.userdetails.User(username,password, authorities);
//
//            // 返回自定义的 KiteUserDetails
//            UserDTO userDTO = new UserDTO(username,password, Collections.singletonList(role));
//            userDTO.setStatus(1);
//            userDTO.setId(11l);
//            userDTO.setClientId("admin-app");
//            SecurityUser user=new SecurityUser(userDTO);
//           return user;
//        }
//    }
//}
